package cc.sjfx.sharedoc.dialog;

import java.util.List;

import cc.sjfx.sharedoc.R;
import cc.sjfx.sharedoc.activity.BasicFragmentActivity;
import cc.sjfx.sharedoc.activity.examination.DetailActivity;
import cc.sjfx.sharedoc.bean.ExamShowListViewBean;
import cc.sjfx.sharedoc.db.ExamDB;
import cc.sjfx.sharedoc.db.bmob.Examination;
import android.app.Dialog;
import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;

public class ExamFilterDialog extends Dialog {
	ListView listView;
	Context context;
	List<Examination> infos;

	public ExamFilterDialog(Context context) {
		super(context, R.style.MyDialog);
		this.context = context;
		setCanceledOnTouchOutside(false);
		setContentView(R.layout.dialog_exam_filter_list);
		listView = (ListView) findViewById(R.id.examFilterListview);

	}

	public void addListData(final List<Examination> infos) {
		this.infos = infos;
		listView.setAdapter(new FilterAdapter());
		listView.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {
				// TODO Auto-generated method stub
				Examination e = infos.get(arg2);
				ExamShowListViewBean bean = ExamDB.getSingleData(e
						.getObjectId());
				Bundle bundle = new Bundle();
				bundle.putSerializable("info", bean);
				bundle.putInt("type", e.getType());
				((BasicFragmentActivity) context).startActivity(bundle,
						DetailActivity.class);
				// dismiss();
			}
		});
	}

	private class FilterAdapter extends BaseAdapter {

		@Override
		public int getCount() {
			// TODO Auto-generated method stub
			return infos.size();
		}

		@Override
		public Object getItem(int arg0) {
			// TODO Auto-generated method stub
			return arg0;
		}

		@Override
		public long getItemId(int arg0) {
			// TODO Auto-generated method stub
			return arg0;
		}

		@Override
		public View getView(int arg0, View arg1, ViewGroup arg2) {
			// TODO Auto-generated method stub
			TextView textView = new TextView(context);
			textView.setTextColor(Color.rgb(0xff, 0xff, 0xff));
			textView.setTextSize(15);
			textView.setText(infos.get(arg0).getTitle());
			return textView;
		}
	}
}
